package com.guet.careapp.controller.rest.common.errorCode;

import com.guet.careapp.common.Constants;

import java.util.HashMap;
import java.util.Map;

import org.springframework.stereotype.Component;

/**
 * Created by LXM on 2017/10/14.
 *
 * @author LXM
 * @version 1.0
 * @description
 * @datetime 20:14
 */
@Component
public class ErrorCodeFactory {

    public static Map<Error, ErrorCode> map;

    static {

        map = new HashMap<>();
        map.put(Error.Success, new ErrorCode(
                Constants.SUCCESS_CODE, Constants.SUCCESS));
        map.put(Error.NotFond, new ErrorCode(
                Constants.NOTFIND_CODE, Constants.NOTFIND));
        map.put(Error.Unkonwn, new ErrorCode(
                Constants.UNKNOWN_CODE, Constants.UNKNOWN));
        map.put(Error.Fail, new ErrorCode(
                Constants.FAIL_CODE, Constants.FAIL));
        map.put(Error.AreadyExist, new ErrorCode(
                Constants.EXIST_ERROR_CODE, Constants.EXIST_ERROR));
        map.put(Error.IsBlank, new ErrorCode(
                Constants.ISBLANK_CODE, Constants.ISBLANK));
        map.put(Error.Invaild, new ErrorCode(
                Constants.INVAILD_CODE, Constants.INVAILD));
        map.put(Error.TimeOut, new ErrorCode(
                Constants.TIMEOUT_CODE, Constants.TIMEOUT));
        map.put(Error.TypeError, new ErrorCode(
                Constants.TYPE_ERROR_CODE, Constants.TYPE_ERROR));


    }

    public static ErrorCode get(Error e) {

        return map.get(e);

    }

}
